<?
require_once("include.php");

$me=false;
require_once("header.session.php");
require_once("header.gui.php");
require_once("header.misc.php");
require_once("header.admin.php");


//globals
$MenuObjects= $me->getMyMenu();

if(!$me) {
	$me=&new Person($_SESSION['id']);
}

if(!isset($_GET['action'])) {
	$_GET['action']="view";
	$_GET['type']="main";
}

if(isset($_POST['action'])) {
	switch($_POST['action']) {
		case "new":
			header("Location: " . $_SERVER['PHP_SELF'] . "?action=edit&type=advisory&id=" . newAdvisory($_POST['name']));
			die;
			break;
		case "changename":
			$advisory=new Advisory($_POST['id']);
			$advisory->changeName($_POST['name']);
			header("Location: " . $_SERVER['PHP_SELF'] . "?action=edit&type=advisory&id=" . $_POST['id']);
			die;
			break;
		case "addstudent":
			$advisory=new Advisory($_POST['id']);
			$advisory->addStudent($_POST['uid']);
			header("Location: " . $_SERVER['PHP_SELF'] . "?action=edit&type=advisory&id=" . $_POST['id']);
			die;
			break;
		case "addadvisor":
			$advisory=new Advisory($_POST['id']);
			$advisory->addAdvisor($_POST['uid']);
			header("Location: " . $_SERVER['PHP_SELF'] . "?action=edit&type=advisory&id=" . $_POST['id']);
			die;
			break;
		case "removemember":
			$advisory=new Advisory($_POST['id']);
			$advisory->removeMember($_POST['uid']);
			header("Location: " . $_SERVER['PHP_SELF'] . "?action=edit&type=advisory&id=" . $_POST['id']);
			die;
			break;
	}
	header("Location: " . $_SERVER['PHP_SELF'] . "?action=" . $_GET['action'] . "&type=" . $_GET['type']);
	die;
}

function Headers() {
	
}

function Body() {
	switch($_GET['action']) {
		case "edit":
			switch($_GET['type']) {
				case "advisory":
					$advisory=new Advisory($_GET['id']);
					echo "
					<form action=\"" . $_SERVER['PHP_SELF'] . "\" method=\"post\">
					<input type=\"hidden\" name=\"action\" value=\"changename\">
					<input type=\"hidden\" name=\"id\" value=\"" . $_GET['id'] . "\">
					<input type=\"text\" name=\"name\" value=\"" . $advisory->info['advisory_name'] . "\">
					<input type=\"submit\" value=\"Change Name\">
					</form>
					<table border=\"0\">
					<tr><td>
					<form action=\"" . $_SERVER['PHP_SELF'] . "\" method=\"post\">
					<input type=\"hidden\" name=\"action\" value=\"addstudent\">
					<input type=\"hidden\" name=\"id\" value=\"" . $_GET['id'] . "\">
					<select name=\"uid\">
					<option value=\"0\">-Select A User-</option>
					";
					$ar=getUserList();
					foreach($ar as $info) {
						if(!$advisory->isStudent($info['people_id']) AND isStudent($info['people_id'])) {
							echo "
					<option value=\"" . $info['people_id'] . "\">" . stripslashes($info['people_firstname']) . " " . stripslashes($info['people_lastname']) . "</option>";
						}
					}
					echo "
					</select>
					<br><input type=submit value=\"Add Student\">
					</form>
					
					
					</td><td>
					
					
					<form action=\"" . $_SERVER['PHP_SELF'] . "\" method=\"post\">
					<input type=\"hidden\" name=\"action\" value=\"addadvisor\">
					<input type=\"hidden\" name=\"id\" value=\"" . $_GET['id'] . "\">
					<select name=\"uid\">
					<option value=\"0\">-Select A User-</option>
					";
					$ar=getUserList();
					foreach($ar as $info) {
						if(!$advisory->isAdvisor($info['people_id']) AND isAdvisor($info['people_id'])) {
							echo "
					<option value=\"" . $info['people_id'] . "\">" . stripslashes($info['people_firstname']) . " " . stripslashes($info['people_lastname']) . "</option>";
						}
					}
					echo "
					</select>
					<br><input type=submit value=\"Add Advisor\">
					</form>
					
					</td></tr>
					
					
					<tr><td>
					<form action=\"" . $_SERVER['PHP_SELF'] . "\" method=\"post\">
					<input type=\"hidden\" name=\"action\" value=\"removemember\">
					<input type=\"hidden\" name=\"id\" value=\"" . $_GET['id'] . "\">
					<select name=\"uid\">
					<option value=\"0\">-Select A User-</option>
					";
					$ar=$advisory->studentList();
					foreach($ar as $info) {
						echo "
					<option value=\"" . $info['people_id'] . "\">" . stripslashes($info['people_firstname']) . " " . stripslashes($info['people_lastname']) . "</option>";
					}
					echo "
					</select>
					<br><input type=submit value=\"Remove Student\">
					</form>
					
					
					</td><td>
					
					
					<form action=\"" . $_SERVER['PHP_SELF'] . "\" method=\"post\">
					<input type=\"hidden\" name=\"action\" value=\"removemember\">
					<input type=\"hidden\" name=\"id\" value=\"" . $_GET['id'] . "\">
					<select name=\"uid\">
					<option value=\"0\">-Select A User-</option>
					";
					$ar=$advisory->advisorList();
					foreach($ar as $info) {
						echo "
					<option value=\"" . $info['people_id'] . "\">" . stripslashes($info['people_firstname']) . " " . stripslashes($info['people_lastname']) . "</option>";
					}
					echo "
					</select>
					<br><input type=submit value=\"Remove Advisor\">
					</form>
					
					</td></tr>
					</table>
					
					";
					break;
			}
			break;
		case "view":
			switch($_GET['type']) {
				case "main":
					echo "
					Here you can edit the assorted advisories...<br />
					<a href=\"" . $_SERVER['PHP_SELF'] . "?action=new\">New Advisory</a><br />
					<table>
					<tr><th>Select Advisory</th></tr>
					";
					$advs = getAdvisoryList();
					foreach($advs as $advisory) {
						echo "<tr><td>
						<a href=\"" . $_SERVER['PHP_SELF'] . "?action=edit&type=advisory&id=" . $advisory['advisory_id'] . "\">" . stripslashes($advisory['advisory_name']) . "</a>
						</td></tr>
						";
					}
					echo "</table>";
					break;
			}
			break;
		case "new":
			echo "
			<form action=\"" . $_SERVER['PHP_SELF'] . "\" method=\"post\" >
			<input type=\"hidden\" name=\"action\" value=\"new\">
			<input type=\"text\" name=\"name\" value=\"Advisory Name\">
			<br />
			<input type=\"submit\" value=\"Create New Advisory\">
			</form>
			";
			break;
	}			
}

include("template.php");

